# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=libsrtp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.4.2
pkgrel=1
pkgdesc="Library for SRTP (Secure Realtime Transport Protocol) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/cisco/libsrtp'
license=('BSD-based')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-pkg-config"
  "${MINGW_PACKAGE_PREFIX}-doxygen"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cisco/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('3b1bcb14ebda572b04b9bdf07574a449c84cb924905414e4d94e62837d22b628')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  # crypto-library-kdf only disabled because it fails to build with openssl
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    -Ddefault_library=both \
    -Dpcap-tests=disabled \
    -Dcrypto-library=openssl \
    -Dcrypto-library-kdf=disabled \
    ../${_realname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}"/build-${CARCH}

  meson test
}

package() {
  cd "${srcdir}"/build-${CARCH}

  DESTDIR="${pkgdir}" meson install
}
